/*
 * XMLHeader.cpp
 *
 *  Created on: Jul 14, 2013
 *      Author: Dan
 */

#include "XMLHeader.h"
#include "parseException.h"

#include <fstream>
#include <iostream>

namespace monkeyXML {

const std::string XMLHeader::XMLHEADER =
		"?xml version=\"1.0\" encoding=\"UTF-8\"?";

XMLHeader::XMLHeader(std::istream& aFileStream) throw (parseException) {

	char current = 0;

	aFileStream.get(current);

	//read off whitespace
	while (current == '\n' || current == ' ' || current == '\r') {
		aFileStream.get(current);
	}

	//read between the <>
	if (current == '<') {
		while (current != '>') {
			theHeader += current;
			aFileStream.get(current);
		}
		theHeader += current;
	} else {
		throw(parseException());
	}
}

XMLHeader::~XMLHeader() {
}

std::string XMLHeader::toString() {
	return "<" + theHeader + ">";
}

XMLHeader::XMLHeader() {
	theHeader = XMLHeader::XMLHEADER;
}

std::string XMLHeader::getTag() {
	return theHeader;
}

} /* namespace myXML */
